package com.chixing.day10_hashcode_exception;

public class Student {
    private int stuId;
    private String stuName;
    private String stuDegree;
    private long stuTel;

    public Student(){}
    public Student(int stuId, String stuName, String stuDegree, long stuTel) {
        this.stuId = stuId;
        this.stuName = stuName;
        this.stuDegree = stuDegree;
        this.stuTel = stuTel;
    }

    public int getStuId() {
        return stuId;
    }

    public void setStuId(int stuId) {
        this.stuId = stuId;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public String getStuDegree() {
        return stuDegree;
    }

    public void setStuDegree(String stuDegree) {
        this.stuDegree = stuDegree;
    }

    public long getStuTel() {
        return stuTel;
    }

    public void setStuTel(long stuTel) {
        this.stuTel = stuTel;
    }

    //重写 equals 方法

    /*@Override
    public boolean equals(Object obj) {
        if (obj == null || this.getClass() != obj.getClass())
            return false;
        if (obj == this)
            return true;
        Student o =(Student) obj;
        if (this.stuId!=o.stuId)//int 10 == 20
            return false;
        if (this.stuName.equals(o.stuName))
            return false;
        if (this.stuDegree.equals(o.stuDegree))
            return false;
        if (this.stuTel!=o.stuTel)// long
            return false;
        return true;
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (stuId != student.stuId) return false;
        if (stuTel != student.stuTel) return false;
        if (stuName != null ? !stuName.equals(student.stuName) : student.stuName != null) return false;
        return stuDegree != null ? stuDegree.equals(student.stuDegree) : student.stuDegree == null;
    }

    @Override
    public int hashCode() {
        int result = stuId;
        result = 31 * result + (stuName != null ? stuName.hashCode() : 0);
        result = 31 * result + (stuDegree != null ? stuDegree.hashCode() : 0);
        result = 31 * result + (int) (stuTel ^ (stuTel >>> 32));
        return result;
    }

    @Override
    public String toString() {
        return "Student{" +
                "stuId=" + stuId +
                ", stuName='" + stuName + '\'' +
                ", stuDegree='" + stuDegree + '\'' +
                ", stuTel=" + stuTel +
                '}';
    }
}
